package com.chujian.servlet;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;



import net.sf.json.JSONArray;

import com.chujian.dao.FoodDao;
import com.chujian.daoImpl.FoodDaoImpl;
import com.chujian.model.Food;

/**
 *  
 * 获取所有菜单列表
 * @author 周映凯
 */
@WebServlet("/MenuServlet")
public class MenuServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	List<HashMap<String, List<Food>>> list = new ArrayList<HashMap<String,List<Food> >>();
	HashMap<String, List<Food>>map=new HashMap<String, List<Food>>();
//	private List<Food> list;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public MenuServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/plain");
		response.setCharacterEncoding("utf-8");
		PrintWriter out=response.getWriter();
		FoodDao foodDao=new FoodDaoImpl();
		
		List<String>categaryList=foodDao.getAllCategary();
		for (String string : categaryList) {
			System.out.println(string);
		}
		for (String str:categaryList) {
			List<Food> foodList=foodDao.qeuryFoodList(str);
			map.put(str, foodList);
		}
		list.add(map);
		
		System.out.println(list.toString());
		JSONArray jsonArray=net.sf.json.JSONArray.fromObject(list);
		
		
		System.out.println(jsonArray.toString());
		out.write(jsonArray.toString());
		out.flush();
		out.close();
		
		
		
		
		
		
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
